﻿
$(function () {
    let form = layui.form
        , laydate = layui.laydate,
        laypage = layui.laypage,
        layer = layui.layer,
        table = layui.table;
    //常规用法
    laydate.render({
        elem: '#test1'
    });
    laydate.render({
        elem: '#test2'
    });
    laydate.render({
        elem:'#range1',
        range: true
    });



    let i = 1, j = 1, k = 1;
    $('.add-btn').click(function () {
        i++;
        addstrs1(i);
        form.render();
    });

    $('.add-btn1').click(function () {
        i++;
        addstrs2(i);
        form.render();
    });

    $('.add-btn2').click(function () {
        i++;
        addstrs3(i);
        form.render();
    });

    $('body').on("click", ".btn-del", function () {
        var pre = $(this);
        layer.confirm('确定要删除么？', {
            btn: ['确定', '取消']
        }, function () {
            $(pre).parent().parent().remove();
            layer.closeAll('dialog');
        })

        //
    });


    function getRandomNum() {
        return parseInt(Math.random() * 50);
    }
    function addstrs1(i) {
        let iNums = getRandomNum();
        let strs1;
        strs1 = '<tr>\n' +
            '                            <td style="display: none">\n' +
            '                                <input type="number" name="number[]" value="' + i + '">\n' +
            '                            </td>\n' +
            '                            <td>\n' +
            '                                <input type="text"  name="Time[]" class="layui-input" id="range1' + iNums + '" placeholder=" - " >\n' +
            '                            </td>\n' +
            '                            <td>\n' +
            '                                <input type="text" name="trip_plan[]" class="layui-input" >\n' +
            '                            </td>\n' +
            '                            <td>\n' +
            '                                <input type="text" name="live_place[]" class="layui-input">\n' +
            '                            </td>\n' +
            '                            <td>\n' +
            '                                <input type="text" name="customer_name[]" class="layui-input">\n' +
            '                            </td>\n' +
            '                            <td>\n' +
            '                                <input type="text" name="item_id[]" class="layui-input">\n' +
            '                            </td>\n' +
            '                            <td style="text-align: center"><button type="button" class="layui-btn layui-btn-sm layui-btn-danger btn-del">删除</button></td>\n' +
            '                        </tr>';
        $('.addlists').append(strs1);
        //重新渲染
        laydate.render({
            elem: '#test1' + iNums
            , trigger: 'click' //采用click弹出
        });
        laydate.render({
            elem: '#test2' + iNums
            , trigger: 'click' //采用click弹出
        });
        laydate.render({
            elem: '#range1' + iNums,
            range:true
            , trigger: 'click' //采用click弹出
        });
    }

    function addstrs2(i) {
        let iNums = getRandomNum();
        let strs1;
        strs1 = '<tr>\n' +
            '                            <td style="display: none">\n' +
            '                                <input type="text" name="number2[]" value="' + i + '">\n' +
            '                            </td>\n' +
            '                            <td>\n' +
            '                                <input type="text"  name="roundtrip[]" class="layui-input" >\n' +
            '                            </td>\n' +
            '                            <td>\n' +
            '                                <input type="text" name="peoplecount[]" class="layui-input">\n' +
            '                            </td>\n' +
            '                            <td>\n' +
            '                                <input type="text" name="arrivetotime[]" class="layui-input">\n' +
            '                            </td>\n' +
            '                            <td>\n' +
            '                                <input type="text" name="flight[]" class="layui-input">\n' +
            '                            </td>\n' +
            '                            <td>\n' +
            '                                <input type="text" name="context[]" class="layui-input">\n' +
            '                            </td>\n' +
            '                            <td style="text-align: center"><button type="button" class="layui-btn layui-btn-sm layui-btn-danger btn-del">删除</button></td>\n' +
            '                        </tr>';
        $('.addlists1').append(strs1);
        //重新渲染
        laydate.render({
            elem: '#test1' + iNums
            , trigger: 'click' //采用click弹出
        });
        laydate.render({
            elem: '#test2' + iNums
            , trigger: 'click' //采用click弹出
        });
    }

    function addstrs3(i) {
        let iNums = getRandomNum();
        let strs1;
        strs1 = '<tr>\n' +
            '                            <td style="display: none">\n' +
            '                                <input type="text" name="number3[]" value="' + i + '">\n' +
            '                            </td>\n' +
            '                            <td>\n' +
            '                                <input type="text"  name="StartTime[]" class="layui-input" id="test1' + iNums + '" >\n' +
            '                            </td>\n' +
            '                            <td>\n' +
            '                                <input type="text" name="onwer[]" class="layui-input" >\n' +
            '                            </td>\n' +
            '                            <td>\n' +
            '                                <input type="text" name="customer[]" class="layui-input">\n' +
            '                            </td>\n' +
            '                            <td>\n' +
            '                                <input type="text" name="detailreason[]" class="layui-input">\n' +
            '                            </td>\n' +
            '                            <td>\n' +
            '                                <input type="text" name="receive[]" class="layui-input">\n' +
            '                            </td>\n' +
            '                            <td>\n' +
            '                                <input type="text" name="businessreason[]" class="layui-input">\n' +
            '                            </td>\n' +
            '                            <td style="text-align: center"><button type="button" class="layui-btn layui-btn-sm layui-btn-danger btn-del">删除</button></td>\n' +
            '                        </tr>';
        $('.addlists2').append(strs1);
        //重新渲染
        laydate.render({
            elem: '#test1' + iNums
            , trigger: 'click' //采用click弹出
        });
        laydate.render({
            elem: '#test2' + iNums
            , trigger: 'click' //采用click弹出
        });
    }

    $()

})
